package com.ruoyi.backend.controller.orderManagement;

import com.ruoyi.backend.domain.orderManagement.ServiceReview;
import com.ruoyi.backend.service.orderManagement.IServiceReviewService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评价管理Controller
 *
 * @author 王冰冰
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/reviewManagement")
public class ServiceReviewController extends BaseController {
    @Autowired
    private IServiceReviewService serviceReviewService;

    /**
     * 查询评价管理列表
     */
    @RequiresPermissions("orderManagement:reviewManagement:list")
    @GetMapping("/list")
    public TableDataInfo list(ServiceReview serviceReview) {
        System.out.println(serviceReview);
        startPage();
        List<ServiceReview> list = serviceReviewService.selectServiceReviewList(serviceReview);
        return getDataTable(list);
    }

    /**
     * 导出评价管理列表
     */
    @RequiresPermissions("orderManagement:reviewManagement:export")
    @Log(title = "评价管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceReview serviceReview) {
        List<ServiceReview> list = serviceReviewService.selectServiceReviewList(serviceReview);
        ExcelUtil<ServiceReview> util = new ExcelUtil<ServiceReview>(ServiceReview.class);
        util.exportExcel(response, list, "评价管理数据");
    }

    /**
     * 获取评价管理详细信息
     */
    @RequiresPermissions("orderManagement:reviewManagement:query")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId) {
        return success(serviceReviewService.selectServiceReviewByReviewId(reviewId));
    }

    /**
     * 新增评价管理
     */
    @RequiresPermissions("orderManagement:reviewManagement:add")
    @Log(title = "评价管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceReview serviceReview) {
        return toAjax(serviceReviewService.insertServiceReview(serviceReview));
    }

    /**
     * 修改评价管理
     */
    @RequiresPermissions("orderManagement:reviewManagement:edit")
    @Log(title = "评价管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceReview serviceReview) {
        return toAjax(serviceReviewService.updateServiceReview(serviceReview));
    }

    /**
     * 删除评价管理
     */
    @RequiresPermissions("orderManagement:reviewManagement:remove")
    @Log(title = "评价管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds) {
        return toAjax(serviceReviewService.deleteServiceReviewByReviewIds(reviewIds));
    }
}